home *** CD-ROM | disk | FTP | other *** search
/ Champak 43 / Vol 43.iso / games / phit.swf / scripts / __Packages / CFreshSoundSystem.as < prev    next >
Encoding:
Text File  |  2007-07-13  |  2.7 KB  |  102 lines

  1. class CFreshSoundSystem
  2. {
  3.    var m_masterSound;
  4.    var m_arrSounds;
  5.    var m_globalSoundHost;
  6.    var m_panCenterX;
  7.    var m_panWidthX;
  8.    var m_isMuted = false;
  9.    var m_masterVolume = 100;
  10.    function CFreshSoundSystem(soundHost)
  11.    {
  12.       this.m_masterSound = new Sound();
  13.       this.m_masterSound.setVolume(this.m_masterVolume);
  14.       this.m_arrSounds = new Array();
  15.       this.m_globalSoundHost = soundHost;
  16.       _root.g_freshSoundSystem = this;
  17.    }
  18.    static function GetInstance()
  19.    {
  20.       return _root.g_freshSoundSystem;
  21.    }
  22.    function SetSpatialPanParameters(centerX, widthX)
  23.    {
  24.       this.m_panCenterX = centerX;
  25.       this.m_panWidthX = widthX;
  26.    }
  27.    function SetMasterVolume(volume)
  28.    {
  29.       volume = MathUtil.Clamp(volume,0,100);
  30.       this.m_masterVolume = volume;
  31.       if(!this.m_isMuted)
  32.       {
  33.          this.m_masterSound.setVolume(this.m_masterVolume);
  34.       }
  35.    }
  36.    function IsMuted()
  37.    {
  38.       return this.m_isMuted;
  39.    }
  40.    function SetMuted(muted)
  41.    {
  42.       this.m_isMuted = muted;
  43.       if(this.m_isMuted)
  44.       {
  45.          this.m_masterSound.setVolume(0);
  46.       }
  47.       else
  48.       {
  49.          this.m_masterSound.setVolume(this.m_masterVolume);
  50.       }
  51.    }
  52.    function GetHostedSoundId(soundId, hostMC)
  53.    {
  54.       return soundId + "~!~" + hostMC._name;
  55.    }
  56.    function PlaySound(soundId, hostMC, panX, nTimesToLoop, offsetSeconds)
  57.    {
  58.       FreshDebug.Assert(soundId != undefined && soundId.length > 0,"soundId");
  59.       if(offsetSeconds == undefined)
  60.       {
  61.          offsetSeconds = 0;
  62.       }
  63.       var _loc2_ = this.m_arrSounds[soundId];
  64.       if(!_loc2_)
  65.       {
  66.          var _loc4_ = undefined;
  67.          if(this.m_globalSoundHost)
  68.          {
  69.             _loc4_ = this.m_globalSoundHost.createEmptyMovieClip("_soundHost" + this.m_globalSoundHost.getNextHighestDepth(),this.m_globalSoundHost.getNextHighestDepth());
  70.          }
  71.          _loc2_ = new Sound(_loc4_);
  72.          _loc2_.attachSound(soundId);
  73.          this.m_arrSounds[soundId] = _loc2_;
  74.       }
  75.       _loc2_.start(offsetSeconds,nTimesToLoop);
  76.       if(panX)
  77.       {
  78.          this.SetSpatialPan(_loc2_,panX);
  79.       }
  80.       return _loc2_;
  81.    }
  82.    function SetSpatialPan(theSound, panX)
  83.    {
  84.       FreshDebug.Assert(theSound != undefined,"SetSpatialPan(): theSound != undefined");
  85.       var _loc2_ = MathUtil.Clamp((panX - this.m_panCenterX) / this.m_panWidthX * 0.5 * 100,-100,100);
  86.       theSound.setPan(_loc2_);
  87.    }
  88.    function StopSound(soundId, hostMC)
  89.    {
  90.       var _loc2_ = this.m_arrSounds[soundId];
  91.       if(!_loc2_)
  92.       {
  93.          return undefined;
  94.       }
  95.       _loc2_.stop(soundId);
  96.    }
  97.    function StopAllSounds()
  98.    {
  99.       stopAllSounds();
  100.    }
  101. }
  102.